/*
 * Общие соседи
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <limits.h>

#ifdef DEBUG
# define debug_fprintf(x)	fprintf x
#else
# define debug_fprintf(x)	((void) 0)
#endif

int
numcmp(const void *p1, const void *p2)
{
	const int a = * (const int *) p1,
	          b = * (const int *) p2;

	if (a < b) return -1;
	if (a > b) return 1;
	return 0;
}

/* {{{ memory allocation wrappers */
extern void *s_calloc(size_t n, size_t size)
{
	void *ptr;
	ptr = calloc(n, size);
	assert(ptr != NULL);
	if (ptr == NULL) {
		debug_fprintf((stderr, "out of memory\n"));
		abort();
	}
	return ptr;
}

extern void *s_malloc(size_t size)
{
	void *ptr;
	ptr = malloc(size);
	assert(ptr != NULL);
	if (ptr == NULL) {
		debug_fprintf((stderr, "out of memory\n"));
		abort();
	}
	return ptr;
}
/* }}} */

/* {{{ autoarray */
typedef struct vector {
	int *data;
	size_t n;
	size_t max;
} vector;
/* {{{ functions */
extern int
vector_init(struct vector *v, int p)
{
	if (v == NULL) {
		fprintf(stderr, "vector_init(): received NULL ptr, not doing anything\n");
		return 1;
	}

	if (p < 0 || p >= (CHAR_BIT * sizeof v->data[0]))
		p = 0;
	v->max = 1 << p;
	v->n = 0;
	v->data = (int *) s_calloc((size_t) v->max, sizeof *v->data);

	return 0;
}

extern int
vector_append(struct vector *v, int a)
{
	int *t = NULL;

	if (v == NULL) {
		fprintf(stderr, "vector_append(): received NULL ptr, not doing anything\n");
		return 1;
	}

	if (v->max == 0)
		vector_init(v, 0);

	if (v->n + 1 > v->max) {
		t = (int *) realloc(v->data, sizeof *t * (v->max *= 2));
		if (!t) {
			fprintf(stderr, "vector_append(): failed to allocate %lu bytes\n", v->max * sizeof *v->data);
			return 1;
		} else {
			v->data = t;
		}
	}

	v->data[v->n++] = a;

	return 0;
}

extern int
vector_sort(struct vector *v, int (*cmpf)(const void *, const void *))
{
	if (v == NULL) {
		fprintf(stderr, "vector_sort(): received NULL ptr, not doing anything\n");
		return 1;
	}

	if (v->max > 0 && v->n > 1) {
		qsort(v->data, (size_t) v->n, sizeof *v->data, cmpf);
		return 0;
	} else {
		return 1;
	}
}

extern int
vector_cleanup(struct vector *v)
{
	if (v == NULL) {
		fprintf(stderr, "vector_cleanup(): received NULL ptr, not doing anything\n");
		return 1;
	}

	if (v->max > 0) {
		v->max = v->n = 0;
		free(v->data);
		v->data = NULL;
		return 0;
	} else {
		return 1;
	}
}
/* }}} */
/* }}} */

/* {{{ doubly-linked list */
typedef struct dll_node {
	int x, y;
	char *data;
	size_t _data_size;
	struct dll_node *prev, *next;
} dll_node;
/* {{{ functions */
/*
 * This function inserts one node pointed to by 'ins' _after_ 'node'.
 */
extern struct dll_node *
dll_insert(struct dll_node *node, struct dll_node *ins)
{
	assert(node != NULL);
	if (ins == NULL) {
		debug_fprintf((stderr, "dll_insert(): ins is NULL, not doing anything\n"));
		return node;
	}

	if (node->next) {
		assert(node->next->prev == node);
		node->next->prev = ins;
	}
	ins->next = node->next;
	ins->prev = node;
	node->next = ins;
	return ins;
}

/*
 * This function extracts 'node' from a doubly-linked list and returns pointer
 * to that node, pointers '->prev' and '->next' are not reset.
 *
 * If you really want to get rid of a node, call
 * 	free(dll_delete(unneeded_node));
 */
extern struct dll_node *
dll_delete(struct dll_node *node)
{
	if (!node) {
		debug_fprintf((stderr, "dll_delete(): received NULL ptr, wtf am i supposed to delete?\n"));
		return NULL;
	}

	if (node->prev) {
		assert(node->prev->next == node);
		node->prev->next = node->next;
	}
	if (node->next) {
		assert(node->next->prev == node);
		node->next->prev = node->prev;
	}

	return node;
}

extern size_t
dll_list_length(struct dll_node *node)
{
	register size_t len = 0;

	while (node) {
		node = node->next;
		len++;
	}

	return len;
}

/*
 * Merge-sort for doubly-linked list.
 *
 * TODO: work out the use of (*cmp)() function
 */
extern void
dll_mergesort(struct dll_node *head, int (*cmp)(const void *, const void *))
{
	struct dll_node *end, *mid;
	struct dll_node *sorted, *first, *second;
	struct dll_node *swap;

	if (head == NULL || head->next == NULL) /* lengths 0, 1 */
		return;

	end = mid = head;
	while (end && end->next && end->next->next) {
		end = end->next->next;
		mid = mid->next;
	}
	if (end && end->next) {
		end = end->next;
		mid = mid->next;
	}

	mid->prev->next = NULL;
	mid->prev = NULL;
	dll_mergesort(head, cmp);
	dll_mergesort(mid, cmp);

	if (cmp(head->data, mid->data) > 0) { /* this is the tricky part */
		char *t1;
		size_t t2;
		struct dll_node *t3;
		int t4;
#define SWAP_(a,b,t) do{(t)=(a),(a)=(b),(b)=(t);}while(0)
		if (head->next && mid->next)
			SWAP_(head->next->prev, mid->next->prev, t3);
		SWAP_(head->x, mid->x, t4);
		SWAP_(head->data, mid->data, t1);
		SWAP_(head->_data_size, mid->_data_size, t2);
		SWAP_(head->prev, mid->prev, t3);
		SWAP_(head->next, mid->next, t3);
#undef SWAP_
	}

	/*
	 * from now on using only ->prev and ->next pointers should suffice us
	 */
	first = head->next;
	if (first) first->prev = NULL;
	second = mid;

	sorted = head;
	sorted->next = NULL;
	assert(sorted->prev == NULL);

	while (first && second) {
		assert(sorted->next == NULL);

		/* TODO: un-copypaste this code (use 'swap' ptr) */
		if (cmp(first->data, second->data) < 0)
			swap = first;
		else
			swap = second;

		assert(swap->prev == NULL);

		sorted->next = swap;
		swap->prev = sorted;
		sorted = swap;

		swap = swap->next;
		if (swap) {
			assert(swap->prev == sorted);
			swap->prev->next = NULL;
			swap->prev = NULL;
		}
	}
	assert(sorted->next == NULL);
	if (first) {
		assert(first->prev == NULL);
		sorted->next = first;
		first->prev = sorted;
	}
	if (second) {
		assert(second->prev == NULL);
		sorted->next = second;
		second->prev = sorted;
	}
}
/* }}} */
/* }}} */

/* {{{ graph repr: adjlist w/ autoarray */
enum vertex_st {
	VTX_ST_UNKN = 0,
	VTX_ST_OPEN,
	VTX_ST_VISITED
};

typedef struct adjlist_vec {
	struct vector v;
	enum vertex_st state;
	int parent;
	int fwd, bck; /* dfs tree depth, >=1 unless uninitialized */
	int low; /* lowpoint(), >=1 unless uninitialized */
} adjlist_vec;
/* {{{ functions */
extern void
adjl_vec_connect(struct adjlist_vec *node, const int conid)
{
	vector_append(&node->v, conid);
}

extern void
adjl_vec_cleanup(struct adjlist_vec *al)
{
	vector_cleanup(&al->v);
}
/* }}} */
/* }}} */

extern struct dll_node *
vector_to_list(struct vector *v)
{
	struct dll_node *head = NULL, *tail = NULL;
	struct dll_node *next;
	register int i;

	if (v == NULL || v->max == 0 || v->n == 0)
		return NULL;

	head = tail = (dll_node *) s_calloc(1UL, sizeof *head);
	head->x = v->data[0];

	for (i = 1; i < v->n; i++) {
		next = (dll_node *) s_calloc(1UL, sizeof *next);
		next->x = v->data[i];
		tail = dll_insert(tail, next);
	}

	return head;
}

/*
 * XXX: Vector 'src' and list '*ptr' must be both sorted prior to calling
 *   this function.
 * XXX: '*ptr' may become NULL.
 */
extern int
intersect_merge(struct dll_node **ptr, struct vector *src)
{
	struct dll_node *dst = *ptr, *nxt = NULL;
	register int i;
	int *set, n;

	if (dst == NULL || src == NULL) {
		debug_fprintf((stderr, "%s():%d: received a NULL ptr\n",
					__func__, __LINE__));
		return -1;
	}

	set = src->data;
	n = src->n;
	i = 0;
	while (dst && i < n) {
		if (dst->x > set[i]) {
			i++;
		} else if (dst->x < set[i]) {
			if (*ptr == dst)
				(*ptr) = (*ptr)->next;
			nxt = dst->next;
			free(dll_delete(dst));
			dst = nxt;
		} else {
			i++;
			dst = dst->next;
		}
		/* no stunts, should be safe */
	}

	return 0;
}

int
main(int argc, char **argv)
{
	struct adjlist_vec *al;
	int i, n, m, v1, v2, k;
	struct dll_node *intersection = NULL;
	int listlen;

	scanf("%d%d", &n, &m);
	al = (adjlist_vec *) s_calloc(n, sizeof *al);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &v1, &v2);
		--v1; --v2;

		adjl_vec_connect(al + v1, v2);
		adjl_vec_connect(al + v2, v1);
	}

	scanf("%d", &k);
	for (i = 0; i < k; i++) {
		scanf("%d", &v1);
		--v1;

		vector_sort(&al[v1].v, numcmp);
		if (i == 0) {
			intersection = vector_to_list(&al[v1].v);
		} else {
			listlen = intersect_merge(&intersection, &al[v1].v);
			if (!intersection)
				break;
		}
	}

	printf("%lu\n", dll_list_length(intersection));
	while (intersection && intersection->next) {
		printf("%d ", intersection->x + 1);
		intersection = intersection->next;
		free(dll_delete(intersection->prev));
	}
	fputc('\n', stdout);
	free(intersection);

	for (i = 0; i < n; i++) {
		adjl_vec_cleanup(al + i);
	}
	free(al);
	return 0;
}
